﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Basic_dictcommit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView(true);
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindGridView(false);
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //实例化字典类
        PM.PMBasic.DictData dict = new PM.PMBasic.DictData();
        if (this.txtAdd.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "教执委名称不能为空！");
            return;
        }
        else
        {
            int result = dict.Insert_DictCommit(this.txtAdd.Text.Trim(),Int32.Parse(this.ddlBack.SelectedValue));
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "教执委添加成功！");
            BindGridView(true);
            this.txtAdd.Text = "";
        }
    }
    /// <summary>
    /// 绑定gridview
    /// </summary>
    /// <param name="GetCount">是否获取总数</param>
    protected void BindGridView(bool GetCount)
    {
        string field = "id,commitee,isuse,case [type] when 1 then '本科' when 2 then '专科' else '其他' end as [type]";
        string where = "";
        if (this.RadioButton1.Checked)
            where = " [type]=1";
        else
            where = " [type]=2";
        PM.Code.Web.controlbind.BindGridViewPublicProc(GridView1, AspNetPager1, "Dict_Commit", "id", field , "id asc", where, GetCount);
    }
    //结束编辑
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        BindGridView(false);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //实例化字典类
        PM.PMBasic.DictData dict = new PM.PMBasic.DictData();
        int id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
        if (e.CommandName == "delcom")
        {
            if (dict.Delete_DictCommit(id) > 0)
            {
                PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "已删除此教执委！");
            }
            BindGridView(true);
        }
        else if (e.CommandName == "open")
        {
            if (dict.Update_DictCommitStatus(id, "True") > 0)
            {
                PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "已启用此教执委！");
            }
            BindGridView(true);
        }
        else if (e.CommandName == "close")
        {
            if (dict.Update_DictCommitStatus(id, "False") > 0)
            {
                PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "已禁用此教执委！");
            }
            BindGridView(true);
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGridView(false);
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //实例化字典类
        PM.PMBasic.DictData dict = new PM.PMBasic.DictData();
        //获取行主键值
        int id = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value);
        //获取修改值
        string commitname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
        if (commitname == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "数据不能为空");
            return;
        }
        dict.Update_DictCommit(commitname, id);
        PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "更新成功！");
        this.GridView1.EditIndex = -1;
        BindGridView(false);
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        BindGridView(true);
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        BindGridView(true);
    }
}
